#pragma once
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include "Util.hpp"
#include <sstream>

using namespace std;

const string sep = "\r\n";
const string default_root = "./wwwroot";
const string home_page = "index.html";

class HttpRequest
{
public:
    HttpRequest()
    {
    }
    ~HttpRequest()
    {
    }
    void parse()
    {
        // 1.从inbuffer中拿到第一行,分隔符\r\n
        string line = Util::getOneLine(inbuffer, sep);
        if (line.empty())
            return;
        // 2.从该行提取三个字段
        stringstream ss(line);
        ss >> method >> url >> httpversion;

        // 3.添加web默认路径
        path = default_root; // ./wwwroot,
        path += url;         //./wwwroot/a/b/c.html, ./wwwroot/
        if (path[path.size() - 1] == '/')
            path += home_page;
    }

public:
    std::string inbuffer;
    // std::string reqline;
    // std::vector<std::string> reqheader;
    // std::string body;

    std::string method;
    std::string url;
    std::string httpversion;
    std::string path;
};
class HttpResponse
{
public:
    std::string outbuffer;
};
